<admintpl file="header" />
</head>

<body class="J_scroll_fixed">
	<div class="wrap J_check_wrap">
		<form id="add_fl_form" method="post" class="J_ajaxForm" action="{:U('AdminTerm/addflitem')}">
			<div class="table-actions">
				<input type="text" class="input inputbox" id="ctext" placeholder="请输入分类名称">
				<button id="fename" class="btn btn-primary btn-small" type="button">添加分类</button>
			</div>
			<table class="table table-hover table-bordered table-list">
				<thead>
					<tr>

						<th width="50">序号</th>
						<th>分类名称</th>
						<th>分类项列表</th>

					</tr>
				</thead>
				<tbody id="tbody">

				</tbody>
			</table>
		</form>

		<div class="form-actions">
			<button class="btn btn-primary btn_submit" type="submit" onclick=submit()>提交</button>
			<a class="btn" href="{:U('AdminTerm/index')}">返回</a>
		</div>
	</div>
	<script type="text/javascript" src="__ROOT__/statics/js/common.js"></script>
	<script>
 
	$('#fename').on('click', function (e) {
	 e.preventDefault();
	  var btn = $(this),
          form = btn.parents('form.J_ajaxForm');
		 
          btn.parent().find('span').remove();
		  var ctext=form.find('input.inputbox').val();
           if (ctext!='') {
           		// alert(form.find('input.inputbox').val());
				  
				   $('<tr><td></td><td><input class="input" name="data[]" value='+ctext+' type="text"  /></button><button class="btn-main-del btn btn-warning btn-small" type="button">删除</button></td><td><div class="btn-con"><input class="input" name="clist[]" type="text"  placeholder="点击右边按钮添加项" /><button class="btn-fl-add btn btn-primary btn-small" type="button">添加</button><button class="btn-fl-del btn btn-warning btn-small" type="button">删除</button></div></td></tr>').appendTo(form.find('table tbody')).fadeIn('fast');
       
		  renum();
		  
		}else{
           	 $('<span class="tips_error">请输入分类名称</span>').appendTo(btn.parent()).fadeIn('fast');
           }

		});

/*添加分类项按钮*/
	$("#tbody").on("click",".btn-fl-add", function() {
		$('<div class="btn-con"><input class="input" name="data[]["a"]" type="text"  placeholder="点击右边按钮添加项" /><button class="btn-fl-add btn btn-primary btn-small" type="button">添加</button><button class="btn-fl-del btn btn-warning btn-small" type="button">删除</button></div><span class="tips_error"></span>').appendTo($(this).parent().parent()).fadeIn('fast');
	});
/*删除分类项按钮*/
$("#tbody").on("click",".btn-fl-del", function() {		
	if($(this).parent().parent().children('.btn-con').length>1){			
		$(this).parent().remove().fadeOut('fast');
	}else{			
	 	$('<span class="tips_error">分类项不能少于一项。</span>').appendTo($(this).parent()).fadeIn('fast');
					//  $(this).parent().text('<span class="tips_error">分类项不能少于一项。</span>').fadeIn('fast');									
		};		
});
/*删除分类项按钮*/
$("#tbody").on("click",".btn-main-del", function() {		
	$(this).parent().parent().remove().fadeOut('fast');
renum();
	

	
    })
/*表格出新生成序号*/
function renum(){
	var length = $("#tbody").find("tr").length;  //#tb为Table的id  获取所有行
            for (i = 0; i < length; i++) {
             $("#tbody tr").eq(i).children("td").eq(0).html(i+1);  //给每行的第一列重写赋值
            }
}
function submit(){
	// $("#add_fl_form").submit();
	var shuju=new Object();
	
var length = $("#tbody").find("tr").length; 
	 for (i = 0; i < length; i++) {
             shuju.namee[i]=$("#tbody tr").eq(i).children("td").eq(1).html();  //给每行的第一列重写赋值
			 shuju.qt[i]="sad";
        }
	console.log(shuju);
};
	</script>
</body>

</html>